﻿<?php
include 'test_header.php' ;

class test_class_db_obj_user extends UnitTestCase{

	static  $test_username = 'test';
	static  $test_passwd = '123456';

	function setUp() {
		$db = db_connect();
		$sql = "
CREATE TABLE IF NOT EXISTS `user` (
  `username` varchar(255) NOT NULL,
  `passwd` varchar(128) NOT NULL,
  `role` varchar(16) NOT NULL,
  `email` varchar(16) NOT NULL,
  `signup_time` varchar(64) DEFAULT NULL,
  `last_signin_time` varchar(64) DEFAULT NULL,
  `last_signin_ipadd` varchar(128) DEFAULT NULL,
  PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8";
		$res = $db->query( $sql );
	}
	function tearDown(){ 
		 
		$db = db_connect();
		$sql = 'DROP TABLE `user`' ;
		$res = $db->query( $sql );
	}

	function test_user_function_save_and_load (){

		$name = rand() ;
		$passwd = "123456";
		$role = "9";

		$db_obj_user = new db_obj_user( db_connect() );
		$db_obj_user->set( 'username'  , $name );
		$db_obj_user->set( 'passwd' , md5($passwd) );
		$db_obj_user->set( 'role' , $role );
		$db_obj_user->set( 'email' , '123@123.123' );

		$this->assertTrue( $db_obj_user->save() );

		//因为确实存在username为'test'的记录,因此
		//断言load(必返回true)
		$this->assertTrue( $db_obj_user->load( 'username' , $name ) );
		
		//断言存入和取出的test用户密码和存入时的一致
		$this->assertEqual( $db_obj_user->get('passwd') , md5('123456') );
	
	}



	

}

$test = new test_class_db_obj_user();
$test->run( new HtmlReporter() );

